﻿using SmartMedicalCare.Infrastructure.Implaction;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SmartMedicalCare.Infrastructure.Information
{
    public class BaseRespository<T>:IBaseRespository<T> where T : class
    {
        private readonly MyDbcontext context;

        public BaseRespository(MyDbcontext context)
        {
            this.context = context;
        }

        public async Task<int> AddAsync(T t)
        {
            await context.Set<T>().AddAsync(t);
            return await context.SaveChangesAsync();
        }

        public async Task<int> DeleleAsync(T t)
        {
            context.Set<T>().Remove(t);
            return await context.SaveChangesAsync();
        }

        public IQueryable<T> GetAll()
        {
            return context.Set<T>().AsQueryable();
        }

        public async Task<int> UpdateAsync(T t)
        {
            context.Set<T>().Update(t);
            return await context.SaveChangesAsync();
        }
    }
}
